package layers.ants;

import events.antEvents.PheromoneStackCreatedEvent;
import events.antEvents.PheromoneStackDestroyedEvent;
import framework.events.EventBroker;

public class PheromoneStack implements AntTickListener{
	
	private long value;
	private final float EVAPORATION_RATE = 0.8f;
	
	public PheromoneStack(long initialValue){
		this.value = initialValue;
	}
	
	private void evaporate(){
		this.value *= EVAPORATION_RATE;
		if(this.value < 1)
			EventBroker.getEventBroker().notifyAll(new PheromoneStackDestroyedEvent(this));
	}

	public void dropPheromones(long value) {
		if(value < 1)
			throw new IllegalArgumentException("Pheromonevalue must larger than 1.");
		if(this.value < 1)
			EventBroker.getEventBroker().notifyAll(new PheromoneStackCreatedEvent(this));
		this.value += value;
	}

	public long getValue() {
		return this.value;
	}

	@Override
	public void processAntTick() {
		this.evaporate();
	}
}
